﻿<Window x:Class="Sample.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="350" Width="525"
        xmlns:VM="clr-namespace:Sample.ViewModel"
        xmlns:WFMVM="clr-namespace:WorkingFileManager.MVVM;assembly=WorkingFileManager.MVVM"
        Title="{Binding WindowTitle}"
        >

    <Window.Resources>

        <!-- below helps us bind recent files menu to a collection of MenuItemViewModels -->
        <Style TargetType="{x:Type MenuItem}">
            <Setter Property="Header" Value="{Binding Path=Header}"/>
            <Setter Property="Command" Value="{Binding Path=Command}"/>
            <Setter Property="CommandParameter" Value="{Binding Path=CommandParameter}"/>
        </Style>
        <HierarchicalDataTemplate DataType="{x:Type WFMVM:MenuItemViewModel}"
                                  ItemsSource="{Binding Path=MenuItems}">
        </HierarchicalDataTemplate>

    </Window.Resources>

    <Grid>
        <Grid.Resources>
            <DataTemplate DataType="{x:Type VM:MainWindowViewModel}" x:Key="dt">

                <DockPanel>

                    <Menu DockPanel.Dock="Top" IsMainMenu="True">
                        <MenuItem Header="File">
                            <MenuItem Header="New" Command="{Binding DefaultFileCommandImplementations.CmdNew}" />
                            <MenuItem Header="Open..." Command="{Binding DefaultFileCommandImplementations.CmdOpen}" />
                            <MenuItem Header="Save" Command="{Binding DefaultFileCommandImplementations.CmdSave}" />
                            <MenuItem Header="Save As..." Command="{Binding DefaultFileCommandImplementations.CmdSaveAs}" />
                            <MenuItem Header="Recent" ItemsSource="{Binding DefaultFileCommandImplementations.RecentFileMenuItemViewModels}" />
                            <MenuItem Header="Exit" Command="{Binding DefaultFileCommandImplementations.CmdExit}" />
                        </MenuItem>
                    </Menu>

                    <TextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" AcceptsReturn="True" />
                    
                    </DockPanel>
            </DataTemplate>
        </Grid.Resources>

        <ContentControl Content="{Binding}" ContentTemplate="{StaticResource dt}" />

    </Grid>
</Window>
